package Day09_Ex1_inheritence_poly;

import java.util.ArrayList;
import java.util.Iterator;

//SPECIAL REVERSE ITERATOR! Could also be a specific iterator to search for; such as MountainBike

public class MyArrayListIterator<T> implements Iterator<T> {

	 private ArrayList<T> list;
	 private int currentPos;
	
	public MyArrayListIterator(ArrayList<T> t)
	{
		list = t;
		currentPos = 0;
	}

	@Override
	public boolean hasNext() {
		return currentPos < list.size();
	}

	@Override
	public T next() { //OUR ITERATOR WORKS IN REVERSE?!
		T el = list.get((list.size()-1-currentPos));
		
		System.out.print("Calling next..............");
		System.out.println(el.getClass().getSimpleName());
		
		currentPos = currentPos + 1;
		return el;
	}

	@Override
	public void remove() {
		throw new UnsupportedOperationException();
	}
}
